resource "aws_internet_gateway" "igw" {
  vpc_id = var.vpc_id
  tags = {
    Name = "${var.igw_name}-igw"
  }
}

resource "aws_route_table" "rtb" {
  vpc_id = var.vpc_id

  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.igw.id
  }

  tags = {
    Name = "${var.igw_name}-rt"
  }
}

resource "aws_route_table_association" "rta" {
  count         = length(var.subnet_ids)
  subnet_id     = var.subnet_ids[count.index]
  route_table_id = aws_route_table.rtb.id
}

